<template>
  <view class="wrap">
    <uv-navbar :fixed="false" title="签到二维码" autoBack safeAreaInsetTop placeholder :border='false'></uv-navbar>
    <view class="box">
      <view class="base">
        <view class="hd">
          <view class="comp">{{ detail.target_name }}</view>
          <view class="time">{{ timeFormat(detail.start_time_text, 'yyyy-mm-dd hh:MM:ss') }}</view>
        </view>
        <view class="qrcode">
          <image :src="codeImage" class="img"></image>
        </view>
        <view class="desc">为减少工作人员压力，请使用微信扫一扫签到</view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app';
import { ref } from 'vue';
import { post } from '@/api';
import { timeFormat } from '@/uni_modules/uv-ui-tools/libs/function/index.js';

let id = '';
let detail = ref({});
let codeImage = ref('');

onLoad((option) => {
  id = option.id;
  getData();
})

function getData(){
  post('api/survey/getSurveyDetail', { survey_id: id }).then(res => {
    if(res.code == 1){
      const data = res.data;
      detail.value = data;
      getCode();
    }
  })
}
function getCode(){
  const params = {
    text: `/pages/invest/code?id=${id}`
  }
  post('api/survey/createSignQrcode', params).then(res => {
    if(res.code == 1){
      const data = res.data;
      codeImage.value = data.qrcode;
    }
  })
}
</script>

<style lang="scss">
  .box{
    padding: 30rpx;
    .base{
      width: 100%;
      border-radius: 32rpx;
      background-color: #fff;
      overflow: hidden;
      padding-bottom: 120rpx;
      .desc{
        font-weight: 400;
        font-size: 28rpx;
        color: #737373;
        text-align: center;
      }
      .qrcode{
        width: 420rpx;
        height: 420rpx;
        margin: 0 auto;
        margin-top: 120rpx;
        margin-bottom: 30rpx;
      }
      .hd{
        background: #E43222;
        height: 190rpx;
        padding: 0 30rpx;
        .time{
          font-weight: 400;
          font-size: 28rpx;
          color: #FFFFFF;
          padding-top: 20rpx;
        }
        .comp{
          font-weight: 500;
          font-size: 32rpx;
          color: #FFFFFF;
          padding-top: 40rpx;
        }
      }
    }
  }
  .wrap{
    width: 100%;
    min-height: 100vh;
    background-color: #F5F5F5;
  }
</style>